﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditWorkFlowFrm.aspx.cs"
    Inherits="WebApp.EditWorkFlowFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>工作流</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/Jquery.Query.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            initParams();
            $('#eOperator').combogrid('setValue', <%=(Session["User"] as WebApp.BaseDataSvc.TB_User).id%>);
        });

        function initParams() {
            var orderId = $.query.get('OrderId');
            var orderCode = $.query.get('OrderCode');
            $('#orderId').val(orderId);
            $('#eOrderCode').val(orderCode);
            initData();
            bindWF();
        }

        function bindWF() {
            var orderId = $('#orderId').val();
            if (orderId) {
                WebApp.EditWorkFlowFrm.GetWF(orderId, function callback(p) {
                    if (p.error) {
                        $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                        return;
                    }

                    var res = p.value;
                    if (res) {
                        var data = res.Data;
                        var msg = res.Msg;
                        if (msg)
                            $.messager.alert('工作流信息获取异常', msg, 'error');
                        else {
                            if (data) {
                                //$('#eOrderCode').val(data.code);
                                $('#eFlowStatus').val(data.flowStatus);
                                $('#eOperator').combogrid('setValue', data.operator);
                                $('#eIsHandle').val(data.isHandle);
                                $('#eComment').val(data.comment);
                                $('#eNextOperator').combogrid('setValue', data.nextOperator);
                            }
                        }
                    }
                });
            }
        }

        function initData() {
            $.getJSON("JSONHandler.ashx?DataType=User", function(result) {
                $('#eOperator').combogrid("grid").datagrid("loadData", result);
                $('#eNextOperator').combogrid("grid").datagrid("loadData", result);
            });
        }

        function confirmWF() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var orderId = $('#orderId').val();
            var op = $('#eOperator').combogrid('getValue');
            var comment = $('#eComment').val();
            WebApp.EditWorkFlowFrm.ConfirmWF(orderId, op, comment, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交回调异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('处理意见信息回调获取异常', msg, 'error');
                    else {
                        //refreshParent(orderId);
                        if (data == true) {
                            $.messager.alert('消息', '处理意见已提交!', 'info');
                        }
                        else
                            $.messager.alert('处理意见提交异常', msg, 'error');

                    }
                }
            });
        }

        function LZWF(isNext) {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var orderId = $('#orderId').val();
            var nextOp = $('#eNextOperator').combogrid('getValue');
            var comment = $('#eComment').val();
            var title = '转交';
            if (!isNext)
                title = '退回';
            WebApp.EditWorkFlowFrm.LZWF(orderId, nextOp, isNext, comment, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交回调异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert(title + '回调获取异常', msg, 'error');
                    else {
                        //refreshParent(orderId);
                        if (data == true) {
                            $.messager.alert('消息', '流程已' + title + '!', 'info');
                        }
                        else
                            $.messager.alert('流程' + title + '异常', msg, 'error');

                    }
                }
            });
        }


        function refreshParent(orderId) {
            window.parent.bindWF(orderId);
        }
    </script>

</head>
<body>
    <form id="Form1" method="post" runat="server">
    </form>
    <div>
        <form id="fm">
        <div style="padding: 5px; width: 500px border: 1px solid #ddd">
            <a href="#" id="btnCommit" class="easyui-linkbutton" data-options="plain:true" onclick="confirmWF()">
                确认处理</a> <a href="#" id="btnNext" class="easyui-linkbutton" data-options="plain:true"
                    onclick="LZWF(true)">转交</a> <a href="#" id="btnBack" class="easyui-linkbutton" data-options="plain:true"
                        onclick="LZWF(false)">退回</a>
        </div>
        <div class="easyui-panel" title="工作流资料" style="width: 500px; padding: 5px;">
            <table>
                <tr>
                    <td style="text-align: left">
                        工作单号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eOrderCode" style="width: 150px;" disabled="disabled" />
                    </td>
                    <td style="text-align: left">
                        流程状态：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eFlowStatus" style="width: 150px" disabled="disabled" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        处理人：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combogrid" required="true" id="eOperator" style="width: 150px"
                            data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[{field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true,
            disabled:true
        ">
                    </td>
                    <td style="text-align: left">
                        处理状态：
                    </td>
                    <td style="text-align: left">
                        <input type="checkbox" id="eIsHandle" style="width: 150px" disabled="disabled" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        处理意见：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eComment" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        下一环节处理人：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combogrid" required="true" id="eNextOperator" style="width: 150px"
                            data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[{field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true
        ">
                    </td>
                </tr>
            </table>
        </div>
        </form>
        <input id="orderId" type="hidden" />
    </div>
</body>
</html>
